const express = require("express");
const router = express.Router();
let app = null;


router.post("/", async function (req, res) {
  let name = req.body.name || "";
  const text = "INSERT INTO users(name, email) VALUES($1, $2) RETURNING *";
  const values = ["brianc", "brian.m.carlson@gmail.com"];

  try {
    const client = await app.locals.pool.connect();

    const ret = await client.query(text, values);
    let data = ret.rows[0];

    client.release();
    console.log(data);

    res.send(data);
  } catch (err) {
    console.log(err.stack);
  }
});

module.exports = function(a){
  app = a;
  return router;
}
